<template>
  <div class="main">
    <div class="title">
      <a class="active" href="/login">登录</a>
      <span>·</span>
      <a href="/register">注册</a>
    </div>

    <div class="sign-up-container">
      <form action="register">
        <div class="input-prepend restyle">
          <input v-model="user.email" type="text" placeholder=" QQ邮箱" />
          <i class="iconfont icon-phone" />
        </div>
        <div class="input-prepend">
          <input v-model="user.password" type="password" placeholder="密码" />
          <i class="iconfont icon-password" />
        </div>
        <div class="btn">
          <input
            type="button"
            class="sign-in-button"
            value="登录"
            @click="submitLogin()"
          />
        </div>
      </form>
      <!-- 更多登录方式 -->
      <div class="more-sign">
        <h6>社交帐号登录</h6>
        <ul>
          <li>
            <a
              id="weixin"
              class="weixin"
              href="http://localhost:8150/api/ucenter/wx/login"
              ><i class="iconfont icon-weixin"
            /></a>
          </li>
          <li>
            <a id="qq" class="qq" target="_blank" href="#"
              ><i class="iconfont icon-qq"
            /></a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import "~/assets/css/sign.css";
import "~/assets/css/iconfont.css";
import login from "../api/login";
import cookie from "js-cookie";
export default {
  layout: "sign",

  data() {
    return {
      user: {
        email: "",
        password: "",
      },
    };
  },

  methods: {
    // 登录
    submitLogin() {
      login.login(this.user).then((resp) => {
        if (resp) {
          let token = resp.data.token;
          if (token != null) {
            cookie.set("token", token);
            this.$message.success("登陆成功！");
            this.$router.push("/");
          } else {
            return this.$message.error(resp.message);
          }
        }
      });
    },
  },
};
</script>
